package com.df.my_net_game.common.utils;

import com.esotericsoftware.reflectasm.MethodAccess;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class HandlerMgr {
    private static HandlerMgr handlerMgr = new HandlerMgr();

    private static ConcurrentHashMap<Integer, HandlerMeta> handlers = new ConcurrentHashMap<>();

    public static void loadHandlers(List<String> handlerPackages){
        //从包下扫描类
        //解析@LgController类的@LgMapper方法
        //路径拼接
    }

    @Data
    private static class HandlerMeta{
        private String path;//路径
        private MethodAccess methodAccess;
        private int methodIndex;
        private Class<?> clazz;//类对象
        private Object instance;//类实例
        private Method method;//方法
        List<Class<?>> params = new ArrayList<>();//参数类型

    }

    public static void HandleMsg(Integer msgId,byte[] msgBytes){
        HandlerMeta handlerMeta = handlers.get(msgId);
        if(handlerMeta == null){
            log.error("未知的消息id："+msgId);
            return;
        }
        //msgBytes处理成对象

//        handlerMeta.methodAccess.invoke(handlerMeta.instance,handlerMeta.methodIndex,)
    }
}
